package com.sx.manage.reserve.thread.threadpool.classify.single;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.sx.manage.reserve.thread.threadpool.classify.Task;
import com.sx.manage.reserve.thread.threadpool.classify.Task30;

/**
 * 创建单一线程的线程池
 * 
 * @author Administrator
 *
 */
public class SingleThreadTest {

	public static void main(String[] args) {
		//
		ScheduledExecutorService singleThread = Executors.newSingleThreadScheduledExecutor(); 
		//每一秒执行一次
		singleThread.schedule(new Task30("t3"), 1, TimeUnit.SECONDS);  
        singleThread.schedule(new Task30("t4"), 1, TimeUnit.SECONDS); 
        //延迟一秒后执行，每一秒执行一次
        singleThread.scheduleAtFixedRate(new Task30("t5"),1, 1, TimeUnit.SECONDS); 
        //关闭线程池
        singleThread.shutdown();
        
		// 声明线程池
		ExecutorService executor = Executors.newSingleThreadExecutor();
		// 执行多线程
		executor.execute(new Task());// 参数为，继承thread或者实现runnable的类
		// 关闭线程池，防止线程泄露
		executor.shutdown();
		
		
	}
}
